{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import fcwt\n",
    "import numpy as np\n",
    "import timeit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "fs = 100\n",
    "\n",
    "n10k = 10000\n",
    "n100k = 100000\n",
    "\n",
    "#Generate signals\n",
    "sig_100k = np.sin(2*np.pi*((0.1+(2*np.arange(n100k))/n100k)*(np.arange(n100k)/fs)))\n",
    "sig_10k = np.sin(2*np.pi*((0.1+(2*np.arange(n10k))/n10k)*(np.arange(n10k)/fs)))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "f0 = 1\n",
    "f1 = 101\n",
    "fn300 = 300\n",
    "fn3000 = 3000\n",
    "\n",
    "#make sure signal is a numpy float array\n",
    "sig_100k = np.array(sig_100k, dtype=np.float32)\n",
    "sig_10k = np.array(sig_10k, dtype=np.float32)\n",
    "\n",
    "#initialize Morlet wavelet with wavelet parameter (sigma) 2.0\n",
    "morl = fcwt.Morlet(2.0)\n",
    "\n",
    "#initialize scales\n",
    "scales300 = fcwt.Scales(morl, fcwt.FCWT_LINFREQS, fs, f0, f1, fn300)\n",
    "scales3000 = fcwt.Scales(morl, fcwt.FCWT_LINFREQS, fs, f0, f1, fn3000)\n",
    "\n",
    "#initialize fcwt\n",
    "nthreads = 8\n",
    "use_optimization_plan = True\n",
    "use_normalization = False\n",
    "fcwt_obj = fcwt.FCWT(morl, nthreads, use_optimization_plan, use_normalization)\n",
    "\n",
    "#initialize output array\n",
    "output_10k_300 = np.zeros((fn300,sig_10k.size), dtype=np.complex64)\n",
    "output_100k_300 = np.zeros((fn300,sig_100k.size), dtype=np.complex64)\n",
    "output_10k_3000 = np.zeros((fn3000,sig_100k.size), dtype=np.complex64)\n",
    "output_100k_3000 = np.zeros((fn3000,sig_100k.size), dtype=np.complex64)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Threads:8\n",
      "Calculating optimal scheme for forward FFT with N:2048\n",
      "Calculating optimal scheme for backward FFT with N:2048\n",
      "Optimization schemes for N: 2048 have been calculated. Next time you use fCWT it will automatically choose the right optimization scheme based on number of threads and signal length.\n",
      "Threads:8\n",
      "Calculating optimal scheme for forward FFT with N:4096\n",
      "Calculating optimal scheme for backward FFT with N:4096\n",
      "Optimization schemes for N: 4096 have been calculated. Next time you use fCWT it will automatically choose the right optimization scheme based on number of threads and signal length.\n",
      "Threads:8\n",
      "Calculating optimal scheme for forward FFT with N:8192\n",
      "Calculating optimal scheme for backward FFT with N:8192\n",
      "Optimization schemes for N: 8192 have been calculated. Next time you use fCWT it will automatically choose the right optimization scheme based on number of threads and signal length.\n",
      "Threads:8\n",
      "Calculating optimal scheme for forward FFT with N:16384\n",
      "Calculating optimal scheme for backward FFT with N:16384\n",
      "Optimization schemes for N: 16384 have been calculated. Next time you use fCWT it will automatically choose the right optimization scheme based on number of threads and signal length.\n",
      "Threads:8\n",
      "Calculating optimal scheme for forward FFT with N:32768\n",
      "Calculating optimal scheme for backward FFT with N:32768\n",
      "Optimization schemes for N: 32768 have been calculated. Next time you use fCWT it will automatically choose the right optimization scheme based on number of threads and signal length.\n",
      "Threads:8\n",
      "Calculating optimal scheme for forward FFT with N:65536\n",
      "Calculating optimal scheme for backward FFT with N:65536\n",
      "Optimization schemes for N: 65536 have been calculated. Next time you use fCWT it will automatically choose the right optimization scheme based on number of threads and signal length.\n",
      "Threads:8\n",
      "Calculating optimal scheme for forward FFT with N:131072\n",
      "Calculating optimal scheme for backward FFT with N:131072\n",
      "Optimization schemes for N: 131072 have been calculated. Next time you use fCWT it will automatically choose the right optimization scheme based on number of threads and signal length.\n"
     ]
    }
   ],
   "source": [
    "fcwt_obj.create_FFT_optimization_plan(100000,\"FFTW_MEASURE\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10k-300:  0.011435500299921842 seconds\n"
     ]
    }
   ],
   "source": [
    "#10k-300\n",
    "a = timeit.timeit('fcwt_obj.cwt(sig_10k, scales300, output_10k_300)', number=10, globals=globals())\n",
    "print(\"10k-300: \", a/10, \"seconds\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100k-300:  0.07430814850004026 seconds\n"
     ]
    }
   ],
   "source": [
    "#100k-300\n",
    "a = timeit.timeit('fcwt_obj.cwt(sig_100k, scales300, output_100k_300)', number=10, globals=globals())\n",
    "print(\"100k-300: \", a/10, \"seconds\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10k-3000:  0.08949035639998329 seconds\n"
     ]
    }
   ],
   "source": [
    "#10k-3000\n",
    "a = timeit.timeit('fcwt_obj.cwt(sig_10k, scales3000, output_10k_3000)', number=10, globals=globals())\n",
    "print(\"10k-3000: \", a/10, \"seconds\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100k-3000:  0.6612934732000213 seconds\n"
     ]
    }
   ],
   "source": [
    "#100k-3000\n",
    "a = timeit.timeit('fcwt_obj.cwt(sig_100k, scales3000, output_100k_3000)', number=10, globals=globals())\n",
    "print(\"100k-3000: \", a/10, \"seconds\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
